package com.zfzs.post.rest;

import com.zfzs.post.common.bean.ResponseResult;
import com.zfzs.post.service.VisitsService;
import com.zfzs.post.utils.RequestHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ck
 * @date 2018-12-13
 */
@RestController
@RequestMapping("api")
public class VisitsController {

    @Autowired
    private VisitsService visitsService;

    @PostMapping(value = "/visits")
    public ResponseResult create() {
        visitsService.count(RequestHolder.getHttpServletRequest());
        return ResponseResult.ok();
    }

    @GetMapping(value = "/visits")
    public ResponseResult get() {
        return ResponseResult.ok(visitsService.get());
    }

    @GetMapping(value = "/visits/chartData")
    public ResponseResult getChartData() {
        return ResponseResult.ok(visitsService.getChartData());
    }
}
